/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view.leftPanels;

import javax.swing.JOptionPane;
import view.centerPanels.NewTableCentralPanel;
import view.main.MainGUI;

/**
 *
 * @author Vlada
 */
public class NewTablePnlLeft extends javax.swing.JPanel {

    public static int numOfAttributes;
    public static int numOfInstances;

    /**
     * Creates new form NewTablePnlLeft
     */
    public NewTablePnlLeft() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblNumAtt = new javax.swing.JLabel();
        txtNumAtt = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        txtNumInst = new javax.swing.JTextField();
        lblNumInstances = new javax.swing.JLabel();

        lblNumAtt.setText("Number of attributes:");

        txtNumAtt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNumAttActionPerformed(evt);
            }
        });

        jButton1.setText("Next");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lblNumInstances.setText("Number of instances:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblNumAtt)
                            .addComponent(lblNumInstances, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNumInst, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNumAtt, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNumAtt)
                    .addComponent(txtNumAtt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNumInst, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNumInstances))
                .addGap(54, 54, 54)
                .addComponent(jButton1)
                .addContainerGap(112, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtNumAttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNumAttActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNumAttActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        try {
            String attributes = txtNumAtt.getText();
        numOfAttributes = Integer.parseInt(attributes);
        String instances = txtNumInst.getText();
        numOfInstances = Integer.parseInt(instances);
        } catch (Exception e) {           
            JOptionPane.showMessageDialog(null, "You must enter numeric values!");
            return;
        }
        
        
        MainGUI.getInstance().getPnlLeft().removeAll();

        AtributeNamesPnlLeft panel = new AtributeNamesPnlLeft();
        panel.setSize(MainGUI.getInstance().getPnlLeft().getSize());
        MainGUI.getInstance().getPnlLeft().removeAll();
        MainGUI.getInstance().getPnlLeft().add(panel);
        MainGUI.getInstance().validate();
        MainGUI.getInstance().repaint();

        panel.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblNumAtt;
    private javax.swing.JLabel lblNumInstances;
    private javax.swing.JTextField txtNumAtt;
    private javax.swing.JTextField txtNumInst;
    // End of variables declaration//GEN-END:variables
}
